import tf2onnx
import tensorflow as tf
# 加载TensorFlow PB模型
with tf.Session() as sess:
    tf.global_variables_initializer().run()
    with open('origin.pb', 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        _ = tf.import_graph_def(graph_def, name='')
# 转换模型
tf2onnx.convert.main([
    '--graphdef', 'origin.pb',
    '--output', 'separator.onnx',
    '--inputs', 'input:0',
    '--outputs', 'output:0'
])